package lc_82_删除排序链表中的重复元素_II;

public class Solution {

	/**
	 * Definition for singly-linked list.
	 */
	public class ListNode {
		int val;
		ListNode next;

		ListNode() {
		}

		ListNode(int val) {
			this.val = val;
		}

		ListNode(int val, ListNode next) {
			this.val = val;
			this.next = next;
		}
	}

	public ListNode deleteDuplicates(ListNode head) {
		ListNode start = new ListNode(0, head);
		ListNode p = start;
		while (p.next != null && p.next.next != null) {
			if (p.next.val == p.next.next.val) {
				while (p.next.next != null && p.next.next.val == p.next.val) {
					p.next.next = p.next.next.next;
				}
				p.next = p.next.next;
			} else {
				p = p.next;
			}
		}
		return start.next;
	}
}